package com.lcg.rocket.web;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: LCG
 * @date: 2023-01-12 13:24:42
 * @description:
 **/
@RestController
public class TestSendController {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @RequestMapping("/test1")
    public void test1(){
        Message msg1 = MessageBuilder.withPayload("rocket 消息过滤测试").build();
        rocketMQTemplate.syncSend("TEST-12",msg1);
    }

    @RequestMapping("/test12/{msg}")
    public void test12(@PathVariable("msg") String msg){
        Message msg1 = MessageBuilder.withPayload("rocket 消息过滤测试 "+msg).build();
        rocketMQTemplate.syncSend("TEST-12",msg1);
    }

    @RequestMapping("/test2")
    public void test2(){
        rocketMQTemplate.convertAndSend("TEST-15","我的消息是。。。。。"+System.currentTimeMillis());
    }

    /**
     * @author: LCG
     * @date: 2023-01-12 18:33:09
     * @description:  发送延时消息
     */
    @RequestMapping("test3/{leval}")
    public void test3(@PathVariable("leval") Integer leval){
        //MessageBuilder.withPayload("消息信息123").
        //发送延时消息
        SendResult sendResult = rocketMQTemplate.syncSend("TEST-15", MessageBuilder.withPayload(leval+"延时消息。。。。。。").build(), 2000,leval);
    }

}
